package jee.boot.module.authority.rest;

import jee.boot.common.basic.TreeController;
import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.common.utils.JsonMapper;
import jee.boot.entity.system.Filter;
import jee.boot.module.authority.service.ResourceService;
import jee.boot.entity.auth.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资源
 */
@RestController
@RequestMapping(value = "/resource")
public class ResourceRestController extends TreeController<ResourceService, Resource> {

    /**
     * 查询当前session用户的所有菜单,树结构,只有菜单类型
     * @return
     */
    @PostMapping("/session/tree")
    public ResponseMessage<List<Resource>> sessionTree() {
        List<Resource>data= service.sessionTree();
        return Result.success(data);
    }
    /**
     * 查询当前session用户的所有资源,列表结构
     * @return
     */
    @PostMapping("/session/list")
    public ResponseMessage<List<Resource>> sessionList() {
        List<Resource>data= service.sessionList();
        return Result.success(data);
    }

    @PostMapping("/newFindList")
    public ResponseMessage<List<Resource>> newFindList(@RequestBody Resource entity) {
        List<Resource> data = service.newFindList(entity);
        return Result.success(data);
    }
    
    @PostMapping("/publishList")
    public ResponseMessage<List<Resource>> publishList(@RequestBody Resource entity) {
        List<Resource> list = service.publishList(entity);
        List<Resource> tree = service.buildTree(list);
        return Result.success(tree);
    }

}